package com.rzjm.exercise.sys.core.log.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.rzjm.exercise.common.base.data.DataTableLayUI;
import com.rzjm.exercise.common.utils.R;
import com.rzjm.exercise.sys.core.log.domain.LogDO;
import com.rzjm.exercise.sys.core.log.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@RequestMapping("/common/log")
@Controller
public class LogController {
	@Resource
	LogService logService;
	String prefix = "common/log";

	@GetMapping()
	String log() {
		return prefix + "/log";
	}

	@ResponseBody
	@GetMapping("/list")
	DataTableLayUI<LogDO> list(@RequestParam Map<String, Object> params) {
		List<LogDO> page = logService.selectByMap(params);
		DataTableLayUI<LogDO> dt = new DataTableLayUI<>();
		dt.setData(page);
		dt.setCount(page.size());
		return dt;
	}

	@ResponseBody
	@PostMapping("/remove")
    R remove(Long id) {
		if (logService.removeById(id)) {
			return R.ok();
		}
		return R.error();
	}

	@ResponseBody
	@PostMapping("/batchRemove")
	R batchRemove(@RequestParam("ids[]") Long[] ids) {
		boolean r = logService.removeByIds(Arrays.asList(ids));
		if (r) {
			return R.ok();
		}
		return R.error();
	}
}
